using System;
using System.Collections.Generic;
using System.Data;
using System.Data.SqlClient;
using System.Web;
using System.Web.Configuration;
using System.Web.Security;
using System.Web.UI;
using System.Web.UI.WebControls;
using TestSystem.BLL;

public partial class News : System.Web.UI.Page
{
    protected void Page_Load(object sender, EventArgs e)
    {
        if (!IsPostBack)
        {
            newsPager.PageSize = Settings.NewsSettings.NewsPageSize;
            newsPager.ItemsCount = TestSystem.BLL.News.News.GetAllCount();
            var isNewsID = Request.QueryString["newsID"];
            var isMode = Request.QueryString["mode"];
            var isFacultyID = Request.QueryString["facultyID"];
            var pageIndex = Request.QueryString["page"];

            if (isNewsID != null)
            {
                newsPager.Visible = false;
                int newsID = int.Parse(Request.QueryString["newsID"]);
                var news = new List<TestSystem.BLL.News.News>();
                news.Add(TestSystem.BLL.News.News.GetByID(newsID));
                lvwNews.DataSource = news;
                lvwNews.DataBind();
            }
            else if (isMode != null)
            {
                newsPager.Visible = false;
                lvwNews.DataSource = TestSystem.BLL.News.News.GetForUniversity();
                lvwNews.DataBind();
            }
            else if (isFacultyID != null)
            {
                newsPager.Visible = false;
                int facultyID = int.Parse(Request.QueryString["facultyID"]);
                lvwNews.DataSource = TestSystem.BLL.News.News.GetByFacultyID(facultyID);
                lvwNews.DataBind();
            }
            else 
            {
                var idx = 0;
                if (pageIndex != null)
                    idx = Convert.ToInt32(Request.QueryString["page"]);
                lvwNews.DataSource = TestSystem.BLL.News.News.GetAll(idx);
                lvwNews.DataBind();
            }
        }
    }
}
